package com.buzz.middleware.dynamic.thread.pool.sdk.trigger.job;

import com.alibaba.fastjson2.JSON;
import com.buzz.middleware.dynamic.thread.pool.sdk.domain.IDynamicThreadPoolService;
import com.buzz.middleware.dynamic.thread.pool.sdk.domain.model.ThreadPoolConfigEntity;
import com.buzz.middleware.dynamic.thread.pool.sdk.registry.IRegistry;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.List;

/**
 * 数据上报任务
 * @Author: LiBaoxuan
 * @CreateTime: 2025-01-05  11:14
 * @Description: TODO
 */
@Slf4j
@AllArgsConstructor
public class ThreadPoolDataReportJob {

    private final IDynamicThreadPoolService dynamicThreadPoolService;
    private final IRegistry registry;

    @Scheduled(cron = "0/20 * * * * ?")
    public void reportJob() {
        List<ThreadPoolConfigEntity> threadPoolConfigEntityList = dynamicThreadPoolService.queryThreadPoolList();
        registry.reportThreadPool(threadPoolConfigEntityList);
        log.info("动态线程池 上报线程池信息:{}", JSON.toJSONString(threadPoolConfigEntityList));
        threadPoolConfigEntityList.forEach(treadPoolConfigEntity -> {
            registry.reportThreadPoolConfigParameter(treadPoolConfigEntity);
            log.info("动态线程池 上报线程池参数:{}", JSON.toJSONString(treadPoolConfigEntity));
        });
    }

}
